<script setup lang='ts'>
import { ref, inject } from "vue";
import { ESClippingPlane, ESPolygonFlattenedPlane, ESViewShed, ESExcavate } from "esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main";
import { createSceneObjTreeItemFromJson } from "../plotting/esObj/fun";
import RightList from "../../components/RightList.vue";
import Button from "../../components/Button.vue";
import { XbsjEarthUi } from "../../scripts/xbsjEarthUi";
const xbsjEarthUi = inject('xbsjEarthUi') as XbsjEarthUi
const objType = ref<string>('')
const createlList: { zh: string, type: string, icon: string, leftButton: boolean }[] = [
    {
        zh: '视阈',
        type: 'ESViewShed',
        icon: 'keshiyu',
        leftButton: true
    },
    {
        zh: '挖坑',
        type: 'ESExcavate',
        icon: 'wakeng',
        leftButton: false

    },
    {
        zh: '压平',
        type: 'ESPolygonFlattenedPlane',
        icon: 'yaping',
        leftButton: true

    },
    {
        zh: '裁剪',
        type: 'ESClippingPlane',
        icon: 'jiancai',
        leftButton: false
    },
    {
        zh: '通视分析',
        type: 'ESVisibilityAnalysis',
        icon: 'tongshifenxi',
        leftButton: true
    },
    {
        zh: '体剖切',
        type: 'ESBoxClipping',
        icon: 'tipaoqie',
        leftButton: false
    }
    
];
const createClippingPlane = (item: { zh: string, type: string, icon: string }) => {
    objType.value = item.type
    const sceneObject = xbsjEarthUi.createSceneObject(item.type) as ESViewShed | ESExcavate | ESPolygonFlattenedPlane | ESClippingPlane
    sceneObject.editing = true
    sceneObject.name = item.zh
    sceneObject.d(sceneObject.editingChanged.disposableOnce(() => {
        if (sceneObject.editing === false) {
            objType.value = ''
            const json = JSON.parse(sceneObject.jsonStr)
            xbsjEarthUi.destroySceneObject(sceneObject)
            createSceneObjTreeItemFromJson(xbsjEarthUi, json)
        }
    }))
}
</script>
<template>
    <RightList :title="'空间分析'">
        <Button v-for="item in createlList" :name="item.icon" :content="item.zh"
            :click="() => { createClippingPlane(item) }" :actived="objType === item.type"
            :left-button="item.leftButton"></Button>
    </RightList>
</template>
